<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="checkbox" id="checkbox" />
    <script>
      const checkbox = document.getElementById("checkbox");
      // if (checkbox.getAttribute("checked") !== null) {
      if (checkbox.checked) {
        console.log("选中");
      } else {
        console.log("未选中");
      }

      setTimeout(() => {
        // ''=> true, null=>false
        console.log(checkbox.getAttribute("checked"));
        console.log(checkbox.checked);
      }, 4000);
    </script>
  </body>
</html>
